<?php
class Users extends CI_Controller{
	public function __construct(){
		parent::__construct();
	}
	public function index(){
		$this->load->view('view_ajax.php');
		//echo "chan";
	}
	public function getData(){
		echo "hello, this is data get from getData function";
	}
	public function show(){
		$this->load->view('paging_view.php');
	}
	public function paging(){
		$data = array();
		$this->load->model('Pagination');
		$record_nums = $this->Pagination->getNums();
		$line_per_page = 1;
		$page_nums = round($record_nums/$line_per_page)	;
		
		if(isset($_GET['page'])){
			$page = $_GET['page'];
			if($page >= 7){
				$start_loop = $page-3;
				if($page_nums > $page + 3){
					$end_loop = $page + 3;
				}elseif ($page<=$page_nums && $page > $page_nums - 6){
					$start_loop = $page_nums - 6;
					$end_loop = $page_nums;
				}else {
					$end_loop = $page_nums;
				}
			}else {
				$start_loop = 0;
				if($page_nums>7){
					$end_loop = 7;
				}else{
					$end_loop = $page_nums;
				}
			}
			$abc = $this->Pagination->keyPaging($line_per_page,$page*$line_per_page);
			
			$data['record_num'] = $record_nums;
			$data['page_num'] = $page_nums;
			$data['start_loop'] = $start_loop;
			$data['end_loop'] = $end_loop;
			$data['database'] = $abc;
			echo json_encode($data);
		}
		
	}
	
}